from django.db import models
from markitup.fields import MarkupField	
from django.utils.translation import ugettext_lazy as _
CHOICE_1=(1, "Answer 1"),(2,"Answer 2"),(3,"Answer 3"),(4,"Answer 4")
CHOICE_2=(1, "Answer 1"),(2, "Answer 2"),(3, "Answer 3"),(4, "Answer 4"),(5, "Answer 5"),(6, "Answer 6"),(7, "Answer 7"),(8, "Answer 8"),(9, "Answer 9"),(10, "Answer 10")
CHOICE_3=(1, "True"),(2, "False")
CHOICE_4=(0, "No Answer"),(1, "Answer 1"),(2, "Answer 2"),(3, "Answer 3"),(4, "Answer 4"),(5, "Answer 5"),(6, "Answer 6"),(7, "Answer 7"),(8, "Answer 8"),(9, "Answer 9"),(10, "Answer 10")
CHOICE_5=(0, "No Answer"),(1, "Section A-B"),(2, "Section B-C"),(3, "Section C-D"),(4, "Section D-E")
# Create your models here.

class ReadingTest(models.Model):
	name = models.CharField("Test name",max_length=500)
	raw_score = models.IntegerField("Raw Total Score",max_length=3)
	def __unicode__(self):
		return self.name
class Passage(models.Model):
	test = models.ForeignKey(ReadingTest)
	title = models.CharField(max_length=200)
	body = MarkupField()
	def __unicode__(self):
		return self.title
class OE(models.Model):
	name  = MarkupField("ANSRE")

class ChooseQuestion(models.Model):
	type = 1
	passage = models.ForeignKey(Passage)
	question = MarkupField()
	answer1= models.CharField("Answer 1", max_length=500)
	answer2= models.CharField("Answer 2", max_length=500)
	answer3= models.CharField("Answer 3", max_length=500)
	answer4= models.CharField("Answer 4", max_length=500)
	correct= models.IntegerField("Correct Answer",max_length=1, choices=CHOICE_1)
	def __unicode__(self):
		id_p = 'Passage name ' + str(self.passage.title)  
		return id_p
	def passage_id(self):
		return self.passage.id

class ChooseTwoQuestion(models.Model): 
	type = 2
	passage= models.ForeignKey(Passage)
	question =  MarkupField()
	answer1 = models.CharField("Answer 1", max_length=500)
	answer2 = models.CharField("Answer 2", max_length=500)
	answer3 = models.CharField("Answer 3", max_length=500)
	answer4 = models.CharField("Answer 4", max_length=500)
	correct1= models.IntegerField("Correct Answer",max_length=1, choices=CHOICE_1)
	correct2= models.IntegerField("Correct Answer",max_length=1, choices=CHOICE_1)
	def __unicode__(self):
		id_p = 'Passage name ' + str(self.passage.title)  
		return id_p;
	def passage_id(self):
		return self.passage.id
class ChooseThreeQuestion(models.Model):
	type = 3
	passage = models.ForeignKey(Passage)
	question =  MarkupField()
	answer1 = models.CharField("Answer 1",max_length=500)
	answer2 = models.CharField("Answer 2",max_length=500)
	answer3 = models.CharField("Answer 3",max_length=500)
	answer4 = models.CharField("Answer 4",max_length=500)
	answer5 = models.CharField("Answer 5",max_length=500,blank=True)
	answer6 = models.CharField("Answer 6",max_length=500,blank=True)
	answer7 = models.CharField("Answer 7",max_length=500,blank=True)
	answer8 = models.CharField("Answer 8",max_length=500,blank=True)
	answer9 = models.CharField("Answer 9",max_length=500,blank=True)
	answer10 = models.CharField("Answer 10",max_length=500,blank=True)
	correct1 = models.IntegerField("Correct Answer 1",max_length=2, choices=CHOICE_2)
	correct2 = models.IntegerField("Correct Answer 2",max_length=2, choices=CHOICE_2)
	correct3 = models.IntegerField("Correct Answer 3",max_length=2, choices=CHOICE_2)
	def __unicode__(self):
		id_p = 'Passage name ' + str(self.passage.title)  
		return id_p;
	def passage_id(self):
		return self.passage.id		
class CheckQuestion(models.Model):
	type = 4
	passage = models.ForeignKey(Passage)
	question = MarkupField()
	answer1 = models.CharField("Answer 1",max_length=500)
	correct1 = models.IntegerField("Correct Answer 1",max_length=1, choices=CHOICE_3)
	answer2 = models.CharField("Answer 2",max_length=500)
	correct2 = models.IntegerField("Correct Answer 2",max_length=1, choices=CHOICE_3)
	answer3 = models.CharField("Answer 3",max_length=500)
	correct3 = models.IntegerField("Correct Answer 3",max_length=1, choices=CHOICE_3)
	answer4 = models.CharField("Answer 4",max_length=500)
	correct4 = models.IntegerField("Correct Answer 4",max_length=1,blank=True, choices=CHOICE_3)
	answer5 = models.CharField("Answer 5",max_length=500,blank=True)
	correct5 = models.IntegerField("Correct Answer 5",max_length=1,blank=True, choices=CHOICE_3)
	answer6 = models.CharField("Answer 6",max_length=500,blank=True)
	correct6 = models.IntegerField("Correct Answer 6",max_length=1,blank=True, choices=CHOICE_3)
	answer7 = models.CharField("Answer 7",max_length=500,blank=True)
	correct7 = models.IntegerField("Correct Answer 7",max_length=1,blank=True, choices=CHOICE_3)
	answer8 = models.CharField("Answer 8",max_length=500,blank=True)
	correct8 = models.IntegerField("Correct Answer 8",max_length=1,blank=True, choices=CHOICE_3)
	def __unicode__(self):
		id_p = 'Passage name ' + str(self.passage.title)  
		return id_p;
	def passage_id(self):
		return self.passage.id
class CategoryQuestion(models.Model):
	type = 5
	categoryCount = models.IntegerField("Category count",max_length=1,default=1, choices=((1, "Single"),(2, "Double")))
	passage = models.ForeignKey(Passage)
	question =  models.TextField()
	choice1 = models.CharField("Answer 1",max_length=500)
	choice2 = models.CharField("Answer 2",max_length=500)
	choice3 = models.CharField("Answer 3",max_length=500)
	choice4 = models.CharField("Answer 4",max_length=500)
	choice5 = models.CharField("Answer 5",max_length=500,blank=True)
	choice6 = models.CharField("Answer 6",max_length=500,blank=True)
	choice7 = models.CharField("Answer 7",max_length=500,blank=True)
	choice8 = models.CharField("Answer 8",max_length=500,blank=True)
	choice9 = models.CharField("Answer 9",max_length=500,blank=True)
	choice10 = models.CharField("Answer 10",max_length=500,blank=True)	
	
	category1 = models.CharField("Category 1",max_length=500)
	c1a1 = models.IntegerField("Category 1 Answer 1",max_length=2, choices=CHOICE_4,default=0)
	c1a2 = models.IntegerField("Category 1 Answer 2",max_length=2, choices=CHOICE_4,default=0)
	c1a3 = models.IntegerField("Category 1 Answer 3",max_length=2, choices=CHOICE_4,default=0)
	c1a4 = models.IntegerField("Category 1 Answer 4",max_length=2,blank=True, choices=CHOICE_4,default=0)
	
	category2 = models.CharField("Category 2",max_length=500, blank=True)
	c2a1 = models.IntegerField("Category 2 Answer 1",max_length=2, choices=CHOICE_4,default=0)
	c2a2 = models.IntegerField("Category 2 Answer 2",max_length=2, choices=CHOICE_4,default=0)
	c2a3 = models.IntegerField("Category 2 Answer 3",max_length=2, choices=CHOICE_4,default=0)
	c2a4 = models.IntegerField("Category 2 Answer 4",max_length=2, choices=CHOICE_4,default=0)

	def __unicode__(self):
		id_p = 'Passage name ' + str(self.passage.title)  
		return id_p;
	def passage_id(self):
		return self.passage.id
class FillQuestion(models.Model):
	type = 4
	passage = models.ForeignKey(Passage)
	question =  MarkupField("Question")
	sectionA =  MarkupField("Section A",blank=True)
	sectionB =  MarkupField("Section B")
	sectionC =  MarkupField("Section C")
	sectionD =  MarkupField("Section D")
	sectionE =  MarkupField("Section E",blank=True)
	answer = models.IntegerField("Answer 1",max_length=2, choices=CHOICE_5,default=0)
	def __unicode__(self):
		id_p = 'Passage name ' + str(self.passage.title)  
		return id_p;
	def passage_id(self):
		return self.passage.id
		
class Score(models.Model):
	user_id = models.IntegerField("User id", max_length=2)
	test_id = models.IntegerField("Test id", max_length=3)
	score = models.IntegerField("Score", max_length=2)
	
class ExamScore(models.Model):
	user_id = models.IntegerField("User id", max_length=3)
	test_id = models.IntegerField("Test id", max_length=3)
	passage_id = models.IntegerField("Passage id", max_length=3)
	passage_index = models.IntegerField("Passage index",max_length=1, choices=((1, "1"),(2,"2"),(3,"3")))	
	score = models.IntegerField("Score", max_length=3)
	time_left = models.IntegerField("Time", max_length=5)
	def __unicode__(self):
		id_p = 'Test ' + str(self.test_id) + " Passage" + str(self.passage_index)
		return id_p;  
class ScoreTable(models.Model):
	test_id = models.ForeignKey(ReadingTest)
	
	toefl = models.IntegerField("Toefl Score", max_length=3)
	raw = models.IntegerField("Raw Score", max_length=3)
	def __unicode__(self):
		id_p = 'Test ' + str(self.test_id) + " Raw" + str(self.raw)
		return id_p;  


class hehe(models.Model):
	category1 = models.CharField("Category 1",max_length=500)
	c1a1 = models.IntegerField("Category 1 Answer 1",max_length=2,blank=True,choices=CHOICE_4,default=0)

class Audio(models.Model):
    audio = models.FileField(_('audio'), upload_to='audios/')
    audio_category = models.CharField(_('audio_category'),max_length=600)

    def __unicode__(self):
        return unicode(str(self.audio).replace('audios/','').replace('.mp3',''))
    
    class Meta:
        verbose_name = _('audio')
        verbose_name_plural = _('audio')
        
class ListeningTest(models.Model):
	name = models.CharField("Test name",max_length=500)
	raw_score = models.IntegerField("Raw Total Score",max_length=3)
	def __unicode__(self):
		return self.name
class ListeningTopic(models.Model):
	test = models.ForeignKey(ListeningTest);
	body = models.FileField(_('audio'), upload_to='audios/topics/')
	def __unicode__(self):
		return str(self.body).replace('audios/topics/','').replace('.mp3','')
		#return str(self.test)
class ListeningChooseQuestion(models.Model):
	type = 1
	topic = models.ForeignKey(ListeningTopic)
	questionAudio = models.FileField(_('question audio'), upload_to='audios/chooses/')
	questionText = models.TextField()
	answer1= models.CharField("Answer 1", max_length=500)
	answer2= models.CharField("Answer 2", max_length=500)
	answer3= models.CharField("Answer 3", max_length=500)
	answer4= models.CharField("Answer 4", max_length=500)
	correct= models.IntegerField("Correct Answer",max_length=1, choices=CHOICE_1)
	def __unicode__(self):
		id_p = str(self.topic.body).replace('audios/topics/','').replace('.mp3',' ') + str(self.questionAudio).replace('audios/chooses/','').replace('.mp3','')
		return id_p
class ListeningChooseTwoQuestion(models.Model): 
	type = 2
	topic= models.ForeignKey(ListeningTopic)
	questionAudio = models.FileField(_('question audio'), upload_to='audios/two/')
	questionText =  models.TextField()
	answer1 = models.CharField("Answer 1", max_length=500)
	answer2 = models.CharField("Answer 2", max_length=500)
	answer3 = models.CharField("Answer 3", max_length=500)
	answer4 = models.CharField("Answer 4", max_length=500)
	correct1= models.IntegerField("Correct Answer",max_length=1, choices=CHOICE_1)
	correct2= models.IntegerField("Correct Answer",max_length=1, choices=CHOICE_1)
	def __unicode__(self):
		id_p = str(self.topic.body).replace('audios/topics/','').replace('.mp3','')  
		return id_p;
class ListeningPreListening(models.Model):
	type = 0
	topic = models.ForeignKey(ListeningTopic)
	questionAudio = models.FileField(_('question audio'), upload_to='audios/pre/')
	questionText = models.TextField()
	def __unicode__(self):
		id_p = str(self.topic.body).replace('audios/topics/','').replace('.mp3',' ') + str(self.questionAudio).replace('audios/pre/','').replace('.mp3','')
		return id_p
class ListeningCheckQuestion(models.Model):
	type = 3
	topic = models.ForeignKey(ListeningTopic)
	questionAudio = models.FileField(_("question audio"), upload_to='audios/check')
	questionText = models.TextField()
	answer1 = models.CharField("Answer 1",max_length=500)
	correct1 = models.IntegerField("Correct Answer 1",max_length=1, choices=CHOICE_3)
	answer2 = models.CharField("Answer 2",max_length=500)
	correct2 = models.IntegerField("Correct Answer 2",max_length=1, choices=CHOICE_3)
	answer3 = models.CharField("Answer 3",max_length=500)
	correct3 = models.IntegerField("Correct Answer 3",max_length=1, choices=CHOICE_3)
	answer4 = models.CharField("Answer 4",max_length=500)
	correct4 = models.IntegerField("Correct Answer 4",max_length=1,blank=True, choices=CHOICE_3)
	answer5 = models.CharField("Answer 5",max_length=500,blank=True)
	correct5 = models.IntegerField("Correct Answer 5",max_length=1,blank=True, choices=CHOICE_3)
	def __unicode__(self):
		id_p = str(self.topic.body).replace('audios/topics/','').replace('.mp3',' ') + str(self.questionAudio).replace('audios/check/','').replace('.mp3','')
		return id_p
class ListeningMatchQueston(models.Model):
	type = 4
	topic = models.ForeignKey(ListeningTopic)
	questionAudio = models.FileField(_("question audio"), upload_to='audios/match')
	questionText = models.TextField()
	choice1 = models.CharField("Answer 1",max_length=500)
	choice2 = models.CharField("Answer 2",max_length=500)
	choice3 = models.CharField("Answer 3",max_length=500)
	choice4 = models.CharField("Answer 4",max_length=500)
	
	
